package com.jzg.jcptadmin.adpter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jzg.jcptadmin.R;
import com.jzg.jcptadmin.app.AppContext;
import com.jzg.jcptadmin.data.vo.CarDetails;
import com.jzg.template.refreshrecycleview.RecycleViewBaseAdapter;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by jzg on 2015/12/24.
 */
public class CarGridViewPhotoAdapter extends RecycleViewBaseAdapter {
    private List<CarDetails.CarPicListEntity> list;
    private AppContext context;
    public CarGridViewPhotoAdapter(AppContext context, List<CarDetails.CarPicListEntity> list) {
        this.context = context;
        this.list = list;
    }
    public void update(int index){
        this.notifyDataSetChanged();
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new CarGridViewPhotoAdapter.MyViewHolder(LayoutInflater.from(context).inflate(R.layout.item_gridview_photo, null));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        CarGridViewPhotoAdapter.MyViewHolder myViewHolder = (CarGridViewPhotoAdapter.MyViewHolder) holder;
        if(list.get(position).getPath().startsWith("http")){
            ImageLoader.getInstance().displayImage(list.get(position).getPath(),myViewHolder.pic,context.options);
        }else{
            ImageLoader.getInstance().displayImage("file:///"+list.get(position).getPath(),myViewHolder.pic);
        }
        myViewHolder.picTitle.setText(list.get(position).getItemName18());
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        ImageView pic;
        RelativeLayout picRelative;
        TextView picTitle;

        public MyViewHolder(View view) {
            super(view);
            pic = (ImageView) view.findViewById(R.id.pic_item);
            picRelative = (RelativeLayout) view.findViewById(R.id.pic_relative);
            picTitle = (TextView) view.findViewById(R.id.picTitle);

        }
    }
}
